﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using SelfMadeMillionaire.Core.Entities;
using SelfMadeMillionaire.Core.Enums;

namespace SelfMadeMillionaire.Web.Infrastructure.ViewModels.MailingList
{
	public class AdminSubscriberViewModel
	{
		public int ID { get; set; }

		[Required]
		[DisplayName("First Name")]
		[RegularExpression(@"^[^\W\d_]+$", ErrorMessage = "Please enter a valid first name")]
		[StringLength(100)]
		public string FirstName { get; set; }

		[Required]
		[DisplayName("Last Name")]
		[RegularExpression(@"^[^\W\d_]+$", ErrorMessage = "Please enter a valid last name")]
		[StringLength(100)]
		public string LastName { get; set; }

		[Required]
		[DataType(DataType.EmailAddress)]
		[RegularExpression(Constants.EMAIL_REGX, ErrorMessage = "Please enter a valid email address")]
		[StringLength(100)]
		public string Email { get; set; }

		public bool IsSMM { get; set; }
		public bool IsMMM { get; set; }

		public bool IsSuccess { get; set; }
        public bool TesterAccount { get; set; }

        public AdminSubscriberViewModel()
        {
        }

        public AdminSubscriberViewModel(Subscriber dbItem)
        {
            if (dbItem != null)
            {
                ID = dbItem.ID;
                FirstName = dbItem.FirstName;
                LastName = dbItem.LastName;
                Email = dbItem.Email;
                TesterAccount = dbItem.TesterAccount;

                if (dbItem.ProductType == (byte)(ProductType.SelfMadeMillionaire | ProductType.MaggiesMoneyMountain))
                {
                    IsMMM = true;
                    IsSMM = true;
                }
                else
                {
                    IsSMM = dbItem.ProductType == (byte)ProductType.SelfMadeMillionaire;
                    IsMMM = dbItem.ProductType == (byte)ProductType.MaggiesMoneyMountain;
                }
            }
        }
	}
}
